package com.qf.redis.controller;

import com.qf.redis.entity.User;
import com.qf.redis.service.IUserService;
import com.qf.redis.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/save")
    public Result save(@RequestBody User user) {
        Boolean save = userService.save(user);
        return Result.ok();
    }

    @PostMapping("/update")
    public Result update(@RequestBody User user) {
        Boolean aBoolean = userService.updateById(user);
        return Result.ok();
    }

    @GetMapping("/info/{id}")
    public Result info(@PathVariable Integer id) {
        User user = userService.info(id);
        return Result.ok(user);
    }

    @GetMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        Boolean aBoolean = userService.removeById(id);
        return Result.ok();
    }

    @GetMapping("/userList")
    public Result userList() {
        List<User> users = userService.listUser();
        return Result.ok(users);
    }
}
